<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>绘制直线</title>
    <style>
        #canvas {
            display: block;
            margin: 50px auto;
            border: 1px solid #000;
        }
    </style>
</head>
<body>
    <canvas id="canvas" width="400" height="400"></canvas>
</body>
<script>

let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');          // 得到2d的画笔
context.moveTo(0, 0);           // 定义了起始的位置
context.lineTo(400, 400);               // 定义了需要画直线的最终目标
context.stroke();           // 开始(行程)


</script>
</html>